//
//  RedemptionViewController.m
//  TenThousand
//
//  Created by 我的 on 16/7/18.
//  Copyright © 2016年 baixue. All rights reserved.
//

#import "RedemptionViewController.h"
#import "EarlyRedemptionViewController.h"
#import "AgreementView.h"
#import "InvestmentVC.h"
#import "InformationViewController.h"
#import "CapitalSubsidiaryViewController.h"

@interface RedemptionViewController ()<UIAlertViewDelegate>
@property (weak, nonatomic) IBOutlet UILabel *Rate;//年利率
@property (weak, nonatomic) IBOutlet UILabel *Dedit;//投资金额
@property (weak, nonatomic) IBOutlet UILabel *profit;//预计收益
@property (weak, nonatomic) IBOutlet UILabel *Term;//期限
@property (weak, nonatomic) IBOutlet UILabel *progrname;
@property (weak, nonatomic) IBOutlet UILabel *qitouriqi;
@property (weak, nonatomic) IBOutlet UILabel *huikuanriqi;
@property (weak, nonatomic) IBOutlet UIButton *redemption;//提前赎回

@end

@implementation RedemptionViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createLeft:[UIImage imageNamed:@"ZHSZicon_03"] leftClick:^{
        [self.navigationController popViewControllerAnimated:YES];
    } right:nil rightClick:nil];
    
    if (self.num == 1) {
        self.navigationItem.title = @"我要投资";
        
        NSLog(@"%@",self.model.BorrowListid);
        
        
        _progrname.text = [NSString stringWithFormat:@"%@:%@",self.model.ProjeceName,self.model.Code];
        _Rate.text = [NSString stringWithFormat:@"%.2f%%",self.model.Rate];
        _Dedit.text = [NSString stringWithFormat:@"%.2f元",[self.model.Amount floatValue]];
        _profit.text = [NSString stringWithFormat:@"%.2f",self.model.profit];
        _Term.text = [NSString stringWithFormat:@"%@",self.model.Tearm];
        _qitouriqi.text = [NSString stringWithFormat:@"%@",self.model.AddDate];//投资日期
        
        _huikuanriqi.text = [NSString stringWithFormat:@"%@",self.model.PaymentDate];
        
        if ([self.model.Fsate isEqualToString:@"投资中"]) {
            _redemption.hidden = YES;
        }

    }else if (self.num == 2){
        self.navigationItem.title = @"已结清";
        _progrname.text = [NSString stringWithFormat:@"%@:%@",self.model.ProjeceName,self.model.Code];
        _Rate.text = [NSString stringWithFormat:@"%.2f%%",self.model.Rate];
        _Dedit.text = [NSString stringWithFormat:@"%.2f元",[self.model.Amount floatValue]];
        _profit.text = [NSString stringWithFormat:@"%.2f%%",self.model.profit];
        _Term.text = [NSString stringWithFormat:@"%@",self.model.Tearm];
        _huikuanriqi.text = [NSString stringWithFormat:@"%@",self.model.AddDate];
        _qitouriqi.hidden = YES;
        
        
        self.redemption.hidden = YES;

    }else if(self.num == 4){
        //已赎回
        self.navigationItem.title = @"已赎回";
        _progrname.text = [NSString stringWithFormat:@"%@:%@",self.model.Project,self.model.Code];
        _Rate.text = [NSString stringWithFormat:@"%.2f%%",self.model.Rate];
        _Dedit.text = [NSString stringWithFormat:@"%.2f元",[self.model.Dedit floatValue]];
        _profit.text = [NSString stringWithFormat:@"%.2f元",self.model.CurrentAmount];
        _Term.text = [NSString stringWithFormat:@"%@",self.model.TeamYear];
        _qitouriqi.text = [NSString stringWithFormat:@"%@",self.model.StartDate];
        _huikuanriqi.text = [NSString stringWithFormat:@"%@",self.model.AddDate];
        
        self.redemption.hidden = YES;

    }
    
    
    
}

//点击提前赎回
- (IBAction)redemption:(id)sender {
    
    
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"确认提前赎回" delegate: nil cancelButtonTitle:@"确定" otherButtonTitles: nil, nil];
    alert.delegate = self;
    [alert show];
   
}


//跳转
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    EarlyRedemptionViewController *earlyView = [[EarlyRedemptionViewController alloc] init];
    [self setHidesBottomBarWhenPushed:YES];
    earlyView.BorrowListId = self.model.BorrowListid;
    earlyView.progrname = _progrname.text;//项目名称
    earlyView.rate = _Rate.text;//lilv
    earlyView.amount = _Dedit.text;//投资金额
    earlyView.yujishouyi = [NSString stringWithFormat:@"%.2f",_model.profit];//预计收益
    earlyView.term = _Term.text;//期限
    earlyView.dangqianshouyi = [NSString stringWithFormat:@"%.2f",[_model.Dqprofit floatValue]];//当前收益
    
    NSArray *dataArr = [_qitouriqi.text componentsSeparatedByString:@" "];
    earlyView.qixiriqi = dataArr[0];//起投日期
     NSArray *jieshuArr = [_huikuanriqi.text componentsSeparatedByString:@" "];
    earlyView.adddata = jieshuArr[0];//回款日期
    earlyView.weiyuejin = [NSString stringWithFormat:@"%.2f",[_model.Weiyuejin floatValue]];//违约金
    earlyView.weiyuejinbili = _model.Rateweiyuejin;//违约金比例
    
    [self.navigationController pushViewController:earlyView animated:YES];
    
}

//点击跳转投资协议
- (IBAction)investNegotiate:(id)sender {
    
    CapitalSubsidiaryViewController *capitalView = [[CapitalSubsidiaryViewController alloc] init];
    capitalView.Borrowid = self.model.Borrowid;
    capitalView.BorrowListId = self.model.BorrowListid;
    capitalView.num = 1;
    capitalView.Code = self.model.Code;
    if (self.num == 4) {
        capitalView.ProjectName = self.model.Project;
    } else {
        capitalView.ProjectName = self.model.ProjeceName;
    }
    [capitalView setSelectIndex: 2];
    [self.navigationController pushViewController:capitalView animated:YES];
    
}

//点击跳转投资记录
- (IBAction)investRecord:(id)sender {
    
    CapitalSubsidiaryViewController *capitalView = [[CapitalSubsidiaryViewController alloc] init];
    capitalView.Borrowid = self.model.Borrowid;
    capitalView.BorrowListId = self.model.BorrowListid;
    capitalView.num = 1;
    capitalView.Code = self.model.Code;
    if (self.num == 4) {
        capitalView.ProjectName = self.model.Project;
    } else {
        capitalView.ProjectName = self.model.ProjeceName;
    }
    [capitalView setSelectIndex: 1];
    [self.navigationController pushViewController:capitalView animated:YES];
    
}
//点击跳转项目详情
- (IBAction)details:(id)sender {
    
    CapitalSubsidiaryViewController *capitalView = [[CapitalSubsidiaryViewController alloc] init];
    capitalView.Borrowid = self.model.Borrowid;
    capitalView.BorrowListId = self.model.BorrowListid;
    capitalView.num = 1;
    capitalView.Code = self.model.Code;
    if (self.num == 4) {
        capitalView.ProjectName = self.model.Project;
    } else {
        capitalView.ProjectName = self.model.ProjeceName;
    }
    [capitalView setSelectIndex: 0];
    [self.navigationController pushViewController:capitalView animated:YES];
}

@end
